<?php
error_reporting(E_ALL);

define('HOST',$_SERVER['HTTP_HOST']);
if(!defined('MEMCACHE_COMPRESSED')){
	define('MEMCACHE_COMPRESSED',2);
}

$sSuffix='.dev.myhome.net';
$sPrefix=str_replace($sSuffix,'',HOST);
$aHost=explode('.',$sPrefix);

$sMiddleDomain=array_pop($aHost);
$sPrefixDomain=join('.',$aHost);
$bShowList=true;

$sCloudPath='/work/app/cloud/';
$aCloudPath=scandir($sCloudPath);
$aClouds=array();
foreach($aCloudPath as $sCloudName){
	if('.'==$sCloudName or '..'==$sCloudName){
		continue;
	}
	if($sCloudName==$sMiddleDomain){
		$bShowList=false;
	}
	$aClouds[]=array( 
			'sCloudName'=>$sCloudName,
			'sUrl'=>'http://'.$sPrefix.'.'.$sCloudName.$sSuffix 
	);
}

if($bShowList){
	print_r($aClouds);
}else{
	define('CODE_BASE_PATH',dirname(__FILE__));
	echo CODE_BASE_PATH.'../';
	exit;
	define('COMMON_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'system'.DIRECTORY_SEPARATOR.'common');
	define('SYS_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'system'.DIRECTORY_SEPARATOR.'kernel');
	define('COMMON_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'system'.DIRECTORY_SEPARATOR.'common'.DIRECTORY_SEPARATOR.'config');
	define('SYS_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'system'.DIRECTORY_SEPARATOR.'kernel'.DIRECTORY_SEPARATOR.'config');
	
	switch(HOST){
		case 'file.dev.myhome.net':
		case 'upd.dev.myhome.net':
			define('APP_NAME','app-file');
			define('APP_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-file');
			define('APP_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-file'.DIRECTORY_SEPARATOR.'config');
			switch(HOST){
				case 'file.dev.myhome.net':
					define('CST_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'file'.DIRECTORY_SEPARATOR.'file');
					$G_LOAD_PATH=array( 
							APP_PATH,
							COMMON_PATH,
							SYS_PATH 
					);
					$G_CONFIG_PATH=array( 
							SYS_CFG_PATH,
							COMMON_CFG_PATH,
							APP_CFG_PATH,
							CST_CFG_PATH 
					);
					break;
				case 'upd.dev.myhome.net':
					define('CST_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'file'.DIRECTORY_SEPARATOR.'upd');
					$G_LOAD_PATH=array( 
							APP_PATH,
							COMMON_PATH,
							SYS_PATH 
					);
					$G_CONFIG_PATH=array( 
							SYS_CFG_PATH,
							COMMON_CFG_PATH,
							APP_CFG_PATH,
							CST_CFG_PATH 
					);
					break;
			}
			break;
		case 'www.dev.myhome.net':
			define('APP_NAME','app-home');
			define('APP_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-home');
			define('APP_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-home'.DIRECTORY_SEPARATOR.'config');
			define('MEM_SHR_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-member-shared');
			define('MEM_SHR_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-member-shared'.DIRECTORY_SEPARATOR.'config');
			define('CST_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'home');
			$G_LOAD_PATH=array( 
					APP_PATH,
					MEM_SHR_PATH,
					COMMON_PATH,
					SYS_PATH 
			);
			$G_CONFIG_PATH=array( 
					SYS_CFG_PATH,
					MEM_SHR_CFG_PATH,
					COMMON_CFG_PATH,
					APP_CFG_PATH,
					CST_CFG_PATH 
			);
			break;
		case 'member.dev.myhome.net':
			define('APP_NAME','app-member');
			define('APP_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-member');
			define('APP_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-member'.DIRECTORY_SEPARATOR.'config');
			define('APP_SHR_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-member-shared');
			define('APP_SHR_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-member-shared'.DIRECTORY_SEPARATOR.'config');
			define('CST_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'member');
			$G_LOAD_PATH=array( 
					APP_PATH,
					APP_SHR_PATH,
					COMMON_PATH,
					SYS_PATH 
			);
			$G_CONFIG_PATH=array( 
					SYS_CFG_PATH,
					COMMON_CFG_PATH,
					APP_SHR_CFG_PATH,
					APP_CFG_PATH,
					CST_CFG_PATH 
			);
			break;
		case 'drama.dev.myhome.net':
			define('APP_NAME','app-drama');
			define('APP_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-drama');
			define('APP_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'app-drama'.DIRECTORY_SEPARATOR.'config');
			define('CST_CFG_PATH',CODE_BASE_PATH.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'drama');
			$G_LOAD_PATH=array( 
					APP_PATH,
					COMMON_PATH,
					SYS_PATH 
			);
			$G_CONFIG_PATH=array( 
					SYS_CFG_PATH,
					COMMON_CFG_PATH,
					APP_CFG_PATH,
					CST_CFG_PATH 
			);
			break;
		default:
			define('APP_NAME','');
			break;
	}
	
	include_once (SYS_PATH.'/bin.php');
	
	main();
}